package com.meritdata.cloud.data.service.development.service.impl;

import com.meritdata.cloud.data.base.Page;
import com.meritdata.cloud.data.service.development.dao.IDataApiDao;
import com.meritdata.cloud.data.service.development.model.DataApi;
import com.meritdata.cloud.data.service.development.service.IDataApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DataApiService implements IDataApiService {

    private static final String LOAD_HQL = "";

    @Autowired
    private IDataApiDao dao;

    @Override
    public void add(DataApi dataApi) {
        dao.save(dataApi);
    }

    @Override
    public List<DataApi> all() {
        return dao.findAll();
    }

    @Override
    public boolean save(DataApi dataApi) {
        Date now = new Date();
        dataApi.setUpdateTime(now);
        dao.save(dataApi);
        return true;
    }

    @Override
    public DataApi get(Long id) {
        return dao.findOne(id);
    }


    @Override
    public boolean delete(Long id) {
        return dao.delete(id) > 0;
    }

    @Override
    public boolean udpate(DataApi dataApi) {
        dataApi.setUpdateTime(new Date());
        dao.update(dataApi);
        return true;
    }

    @Override
    public Page page(Page page) {
        return dao.pageHql(LOAD_HQL, page.getPageNum(), page.getPageSize(), null);
    }

}
